<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>复选框</title>
</head>
<body>
  <input type="checkbox" class="x">
  <input type="checkbox" class="x">
  <input type="checkbox" class="x">
  <br>
  <button onclick="a()">全选</button>
  <button onclick="b()">不选</button>
  <button onclick="c()">反选</button>
  <script type="text/javascript">
    var x = document.getElementsByClassName('x')
    function a() {
      for (let i in x) x[i].checked = true;
    }
    function b() {
      for (let i in x) x[i].checked = false;
    }
    function c() {
      for (let i in x) x[i].checked = !x[i].checked;
    }
  </script>
</body>
</html>